<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Using Scala</title>
</head>

<body>

<h2>Writing Steps in Scala</h2>

<p><a href="http://scala-lang.org">Scala</a> is the new kid on the block
that compiles directly to the JVM.</p>

<p>JBehave supports writing Steps classes directly in Scala, using the <a
    href="javadoc/scala/org/jbehave/core/steps/scala/ScalaStepsFactory.html">ScalaStepsFactory</a>
    and providing the list of Scala classes found in the classpath:
</p>
<script type="syntaxhighlighter" class="brush: java">
<![CDATA[
public class ScalaStories extends JUnitStories {

    @Override
    public Configuration configuration() {
        return new MostUsefulConfiguration()
                .useStoryReporterBuilder(new StoryReporterBuilder().withFormats(ANSI_CONSOLE));
    }

    @Override
    protected List<String> storyPaths() {
        return new StoryFinder()
                .findPaths(codeLocationFromClass(this.getClass()), "**/*.story", "");
    }

    @Override
    public InjectableStepsFactory stepsFactory() {
        return new ScalaStepsFactory(configuration(), new ScalaContext("ScalaSteps"));
    }

}
]]>
</script>

<span class="followup">The Scala classes must be compiled directly into Java bytecode.</span>

<p>The Scala steps classes contain annotated methods, just as you would in Java:</p>
<script type="syntaxhighlighter" class="brush: scala">
<![CDATA[
class ScalaSteps {
    
  @org.jbehave.core.annotations.Given("a date of $date")
  def aDate(date: java.util.Date) {
     org.junit.Assert.assertNotNull(date)
  }

  @org.jbehave.core.annotations.When("$days days pass")
  def daysPass(days: Int) {
     org.junit.Assert.assertNotNull(days)
  }

  @org.jbehave.core.annotations.Then("the date is $date")
  def theDate(date: java.util.Date) {
     org.junit.Assert.assertNotNull(date)
  }

  override def toString(): String = "ScalaSteps";

}
]]>
</script>

<div class="clear">
<hr />
</div>
</body>
</html>
